package designPattern.behavioralPattern.chainOfResponsibility.每个处理者都要处理;

public class Chain {

    //初始化链的头部
    public HandlerContext head = new HandlerContext(
            (context, arg) -> context.runNext(arg)
    );

    //添加节点到尾部
    public void addLast(Handler handler) {
        HandlerContext context = head;
        while (context.getNext() != null) {
            context = context.getNext();
        }
        context.setNext(new HandlerContext(handler));
    }

    //开始执行
    public void request(Object arg) {
        this.head.handler(arg);
    }

}



